< Prev(J) / Next(K) > / View :

Filename: /text/sbasic/shared/03020204.xhp

(section: put) (bookmark: bm_id3150360)
Put statement

Put ステートメント

Put Statement [Runtime]
Put ステートメント [実行時](hd_id3150360.1)

Writes a record to a relative file or a sequence of bytes to a binary file.
相対編成ファイルへの 1 つのレコードの書き込みおよび、バイナリファイルへの 1 つのバイトシーケンスの書き込みが行えます。(par_id3154909.2)

(/section: put)

See also: Get statement
次も参照してください: Get ステートメント(par_id3156281.3)

Syntax:
構文:(hd_id3125863.4)

Put [#] FileNumber As Integer, [position], Variable
Put [#] FileNumber As Integer, [position], Variable(par_id3155132.5)

Parameters:
パラメータ:(hd_id3153190.6)

FileNumber: Any integer expression that defines the file that you want to write to.
FileNumber: 書き込むファイルを指定する整数表式。(par_id3146120.7)

Position: For relative files (random access files), the number of the record that you want to write.
Position:相対編成ファイル (ランダムアクセスファイル) の場合は、書き込むレコードの番号。(par_id3155411.8)

For binary files (binary access), the position of the byte in the file where you want to start writing.
バイナリファイル (バイナリアクセス) の場合は、ファイル中の書き込みを開始するバイト位置。(par_id3148576.9)

Variable: Name of the variable that you want to write to the file.
Variable: ファイルに書き込む変数の名前。(par_id3153729.10)

Note for relative files: If the contents of this variable does not match the length of the record that is specified in the Len clause of the Open statement, the space between the end of the newly written record and the next record is padded with existing data from the file that you are writing to.
相対編成ファイルでの注意: この変数の内容が Open ステートメントの Len句で指定されたレコード長と一致しない場合、 新たに書き込まれたレコードの末尾から次のレコードまでの間の空間は、書き込み先ファイルの既存データで埋められます。(par_id3146974.11)

Note for binary files: The contents of the variables are written to the specified position, and the file pointer is inserted directly after the last byte. No space is left between the records.
バイナリファイルについては、下記の点に注意が必要です。ここで指定する変数の内容は、指定位置から書き込みが開始され、データの最終バイトの次にファイルポインタが移動します。レコードの間に、スペースが残されることはありません。(par_id3155855.12)

Example:
例:(hd_id3154491.13)

Sub ExampleRandomAccess
Sub ExampleRandomAccess(par_id3149410.14)

Dim iNumber As Integer
Dim iNumber As Integer(par_id3149959.15)

Dim sText As Variant REM Must be a variant type
Dim sText As Variant REM バリアント型変数が必要(par_id3154729.16)

Dim aFile As String
Dim aFile As String(par_id3156286.17)

aFile = "c:\data.txt"
aFile = "c:\data.txt"(par_id3149400.18)

iNumber = Freefile
iNumber = Freefile(par_id3149124.20)

Open aFile For Random As #iNumber Len=32
Open aFile For Random As #iNumber Len=32(par_id3150330.21)

Seek #iNumber,1 REM Position to start writing
Seek #iNumber,1 REM 書き込み開始位置(par_id3156278.22)

Put #iNumber,, "This is the first line of text" REM Fill line with text
Put #iNumber,, "ここはテキストの始めの行です。" REM テキストで行を埋める(par_id3153711.23)

Put #iNumber,, "This is the second line of text"
Put #iNumber,, "This is the second line of text"(par_id3155446.24)

Put #iNumber,, "This is the third line of text"
Put #iNumber,, "This is the third line of text"(par_id3154255.25)

Seek #iNumber,2
Seek #iNumber,2(par_id3150045.26)

Get #iNumber,,sText
Get #iNumber,,sText(par_id3145149.27)

Print sText
Print sText(par_id3147363.28)

Close #iNumber
Close #iNumber(par_id3163806.29)

iNumber = Freefile
iNumber = Freefile(par_id3149568.31)

Open aFile For Random As #iNumber Len=32
Open aFile For Random As #iNumber Len=32(par_id3155607.32)

Get #iNumber,2,sText
Get #iNumber,2,sText(par_id3154022.33)

Put #iNumber,,"This is new text"
Put #iNumber,,"This is new text"(par_id3150940.34)

Get #iNumber,1,sText
Get #iNumber,1,sText(par_id3146132.35)

Get #iNumber,2,sText
Get #iNumber,2,sText(par_id3154198.36)

Put #iNumber,20,"This is the text in record 20"
Put #iNumber,20,"This is the text in record 20"(par_id3159102.37)

Print Lof(#iNumber)
Print Lof(#iNumber)(par_id3153785.38)

Close #iNumber
Close #iNumber(par_id3151277.39)

end sub
end sub(par_id3150786.41)


< Prev / Next >